/*
 * @Description  :
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2022-03-14 14:17:38
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-04-11 21:33:13
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\ticket-management\\components\\etc-invoiced-list\\transaction-details\\transaction-details.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STComponent, STColumn, STChange, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFDateWidgetSchema, SFSchema } from '@delon/form';
import { NzModalService } from 'ng-zorro-antd/modal';
import { TicketService } from '../../../services/ticket.service';
@Component({
  selector: 'app-ticket-management-apply-record-list-ticket',
  templateUrl: './apply-record-list-ticket.component.html'
})
export class TicketManagementApplyRecordListTicketComponent implements OnInit {
  data: any = [];
  tableList: any = [];
  tableList2: any = [];
  selectedData = [];
  url = `/api/fcc/ficoVatappH/queryShipperVatappHOverTicketList`;
  url2 = `/api/fcc/ficoVatappH/getDetailByVatinvHId`;
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('stFloat', { static: true })
  stFloat!: STComponent;
  columns: STColumn[] = [];
  columnsFloat: STColumn[] = [];
  isVisible = false;

  constructor(public service: TicketService, private nzModalService: NzModalService, private router: Router) {}
  beforeReq = (requestOptions: STRequestOptions) => {
    Object.assign(requestOptions.body,  {
      vatappHCode: this.data.vatappcode,
      sts: '3',
      ltdId: '',
      invoicetype: '',
      invoicedate: {
        start: '',
        end: ''
      }});
    return requestOptions;
  };
  ngOnInit(): void {
    console.log(this.data);
          this.initST();

    // if (this.data) {
    //   this.service
    //     .request(this.url, {
    //       vatappHCode: this.data.vatappcode,
    //       sts: '3',
    //       pageIndex: 1,
    //       pageSize: 10000,
    //       ltdId: '',
    //       invoicetype: '',
    //       invoicedate: {
    //         start: '',
    //         end: ''
    //       }
    //       // pageIndex: 1,
    //       // pageSize: 100,
    //       // sts: '3',
    //       // vatappHCode: 'VP202205111419334296',
    //       // ltdId: '',
    //       // invoicetype: '',
    //       // invoicedate: {
    //       //   start: '',
    //       //   end: ''
    //       // }
    //     })
    //     .subscribe(res => {
    //       console.log(res);
    //       this.tableList = res.records;
    //       this.initST();
    //     });
    // }
  }
  initST() {
    this.columns = [
      { title: '发票号码', index: 'invoiceno', width: '120px' },
      { title: '发票代码', index: 'invoiceno2', width: '120px' },
      { title: '申请时间', index: 'createTime', type: 'date', width: '120px' },
      { title: '发票类型', index: 'invoicetypeLabel', className: 'text-center', width: '120px' },
      { title: '网络货运人', index: 'ltdName', width: '120px' },
      { title: '购买人', index: 'artoname', width: '120px' },
      { title: '订单数', index: 'ordlines', className: 'text-right', width: '120px' },
      {
        title: '价税合计',
        index: 'vatmoney',
        width: '120px',
        type: 'widget',
        className: 'text-right',
        widget: { type: 'currency-chy', params: ({ record }) => ({ value: record.vatmoney }) }
      },
      {
        title: '金额',
        index: 'vatnotax',
        width: '120px',
        type: 'widget',
        className: 'text-right',
        widget: { type: 'currency-chy', params: ({ record }) => ({ value: record.vatnotax }) }
      },
      {
        title: '税率',
        index: 'billvatrate',
        className: 'text-right',
        width: '120px',
        format: item => `${item.billvatrate ? ((item.billvatrate as number) * 100).toFixed(2) : 0}%`
      },
      {
        title: '税额',
        index: 'vattax',
        width: '120px',
        type: 'widget',
        className: 'text-right',
        widget: { type: 'currency-chy', params: ({ record }) => ({ value: record.vattax }) }
      },
      { title: '开票日期', index: 'invoicedate', type: 'date', width: '120px' },
      {
        title: '快递信息',
        render: 'expresscompany',
        width: '120px'
      },
      { title: '状态', index: 'stsLabel', width: '120px' },
      {
        title: '操作',
        fixed: 'right',
        className: 'text-center',
        width: '120px',
        buttons: [
          { type: 'divider' },
          {
            text: '查看明细<br>',
            click: item => {
              this.isVisible = true;
              this.service.request(this.url2, { id: item.id }).subscribe(res => {
                console.log(res);
                this.tableList2 = res.records;
                this.initSTFloat();
              });
            }
          }
        ]
      }
    ];
  }
  handleCancel(type: string) {
    this.isVisible = false;
  }
  beforeReq2 = (requestOptions: STRequestOptions) => {
    const a: any = {};

    const params: any = Object.assign({});
    delete params._$expand;

    return requestOptions;
  };
  initSTFloat() {
    this.columnsFloat = [
      { title: '服务名称', render: 'vatnameLabel', width: '350px' },
      { title: '规格型号', render: 'vatmodel', width: '300px' },
      { title: '单位', render: 'vatunit', width: '60px' },
      { title: '数量', render: 'vatqty', width: '100px', className: 'text-right' },
      {
        title: '金额',
        index: 'vatmoney',
        width: '100px',
        type: 'widget',
        className: 'text-right',
        widget: { type: 'currency-chy', params: ({ record }) => ({ value: record.vatmoney }) }
      },
      {
        title: '税率',
        index: 'vatrate',
        width: '100px',
        className: 'text-right',
        format: item => `${item.vatrate ? ((item.vatrate as number) * 100).toFixed(2) : 0}%`
      },
      {
        title: '税额',
        index: 'vattax',
        width: '100px',
        type: 'widget',
        className: 'text-right',
        widget: { type: 'currency-chy', params: ({ record }) => ({ value: record.vattax }) }
      }
    ];
  }
}
